from swampy.TurtleWorld import *
import math
def square(t):
    for i in range(4):
        fd(t,100)
        lt(t)

def square(t, length):
    for i in range(4):
        fd(t,length)
        lt(t)

def polyline(t, length, n, angle):
    """
    Draw n line segments with the given length and
    angle (in degrees) between them. t is a turtle.
    """
    for i in range(n):
        fd(t,length)
        lt(t, angle)

def polygon(t, length, n):
    angle = 360.0/n
    polyline(t, length, n, angle)
    
#def circle(t, r):
#    circumference = 2*math.pi*r
#    n = int(circumference / 2)
#    length = circumference / n   
#    polygon(t, length, n)

def arc(t, r, angle):
    arclength = 2 * math.pi * r * angle /360
    n = int(arclength / 2)
    length = arclength / n
    polyline(t, length, n, float(angle)/n)

def circle(t, r):
    arc(t, r, 360)
        
